#[macro_export]
macro_rules! api_get {
    ($fn:ident, $form:ident, $get_fn:expr) => {
        async fn $fn(pool: web::Data<DbPool>, form: web::Path<$form>) -> Result<impl Responder> {
            let item = $get_fn(pool, form.slug.clone())
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(item))
        }
    };
}

#[macro_export]
macro_rules! api_get_relevant {
    ($fn:ident, $form:ident, $get_fn:expr) => {
        async fn $fn(pool: web::Data<DbPool>, form: web::Path<$form>) -> Result<impl Responder> {
            let item = $get_fn(pool, form.slug.clone())
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(item))
        }
    };
}

#[macro_export]
macro_rules! api_get_in_page {
    ($fn:ident, $form:ident, $gets_page_fn:expr) => {
        async fn $fn(pool: web::Data<DbPool>, form: web::Path<$form>) -> Result<impl Responder> {
            let items = $gets_page_fn(pool, get_page_size(), form.page)
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(items))
        }
    };
}

#[macro_export]
macro_rules! api_get_relevant_in_page {
    ($fn:ident, $form:ident, $gets_slug_page_fn:expr) => {
        async fn $fn(pool: web::Data<DbPool>, form: web::Path<$form>) -> Result<impl Responder> {
            let items = $gets_slug_page_fn(pool, form.slug.clone(), get_page_size(), form.page)
                .await
                .map_err(ErrorInternalServerError)?;
            Ok(web::Json(items))
        }
    };
}
